unit OftenBooks;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, IBQuery;

type
  TfmOftenBooks = class(TForm)
    Label1: TLabel;
    edtMinTimesGiven: TEdit;
    rbYear: TRadioButton;
    rbMonth: TRadioButton;
    rbDays: TRadioButton;
    edtDays: TEdit;
    Label2: TLabel;
    btnReport: TButton;
    procedure btnReportClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation
uses ExcelReport, DataModule, DicDM;
{$R *.DFM}

procedure TfmOftenBooks.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfmOftenBooks.btnReportClick(Sender: TObject);
var rep: TxlReport;
  q: TIBQuery;
  date1: TDateTime;
begin
  q := dmDic.CreateQuery(Self);
  q.SQL.Text := 'SELECT * FROM OFTEN_BOOKS(:min_times_given, :date1)';
  q.ParamByName('min_times_given').AsInteger := StrToInt(edtMinTimesGiven.Text);
  if rbYear.Checked then
    date1 := Date() - 365
  else if rbMonth.Checked then
    date1 := Date - 31
  else
    date1 := Date - StrToInt(edtDays.Text);
  q.ParamByName('date1').AsDate := date1;
  //
  rep := TxlReport.Create;
  rep.Template := RepDir + '\OftenBooks.xls';
  rep.Query := q;
  try
    rep.Execute(True);
  finally
    rep.Free;
    q.Free;
  end;
end;

end.
